package com.nanfang51g3.ckz.adapter.ext;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.nanfang51g3.ckz.R;
import com.nanfang51g3.ckz.adapter.base.BaseRecyclerViewAdapter;
import com.nanfang51g3.ckz.domain.RightTypeBean;
import com.nanfang51g3.ckz.utils.KLog;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/4/19.
 */
public class HomeRightAdapter extends BaseRecyclerViewAdapter<RightTypeBean, HomeRightAdapter.HomeViewHolder> {

    public HomeRightAdapter(List<RightTypeBean> list) {
        super(list);
    }


    @Override
    protected void bindDataToItemView(final HomeViewHolder myViewHolder, final RightTypeBean item) {
        myViewHolder.setText(R.id.right_fragment_type, item.getTypeName());
        KLog.i("VB", " bindDataToItemView - " + item.getTypeName() + "-" + item.isSelect());
        TextView textView = myViewHolder.getView(R.id.right_fragment_dian);
        if (item.isSelect()) {
            textView.setVisibility(View.VISIBLE);
        } else {
            textView.setVisibility(View.INVISIBLE);
        }
    }


    @Override
    public HomeViewHolder onCreateViewHolder(ViewGroup viewGroup, int type) {

        return new HomeViewHolder(inflateItemView(viewGroup, R.layout.home_right_item));

    }

    public class HomeViewHolder extends BaseRecyclerViewAdapter.SparseArrayViewHolder {
        public HomeViewHolder(View itemView) {
            super(itemView);
        }
    }

    public void notifyItem(String name, boolean isSelect) {
        ArrayList<RightTypeBean> strings = (ArrayList<RightTypeBean>) super.mList;
        for (RightTypeBean rightTypeBean : strings) {
            if (rightTypeBean.isSelect() && !rightTypeBean.getTypeName().equals(name)) {
                KLog.i("VB", "strings - if - 1" + rightTypeBean.isSelect() + "-" + rightTypeBean.getTypeName());
                rightTypeBean.setSelect(false);
            }
            if (rightTypeBean.getTypeName().equals(name)) {
                KLog.i("VB", "strings - if - 2" + name);
                rightTypeBean.setSelect(true);
            }
        }
        KLog.i("Evd", "size=" + strings.size());
        super.addList(strings);

    }
}
